package com.dff.jrfw;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.dff.jrfw.common.Constant;
import com.dff.jrfw.databinding.ActivityModifyLoginPsdStepThreeBinding;
import com.dff.jrfw.model.LoginAccountRecordModel;
import com.dff.jrfw.utils.AppManager;
import com.dff.jrfw.utils.CountDownHelper;
import com.dff.jrfw.utils.GsonUtils;
import com.dff.jrfw.utils.SharedPreferenceUtils;

import java.util.ArrayList;

public class ModifyLoginPsdStepThreeActivity extends BaseActivity implements View.OnClickListener {

    private ActivityModifyLoginPsdStepThreeBinding binding;

    public static void callMe(Context context) {
        Intent intent = new Intent(context, ModifyLoginPsdStepThreeActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_modify_login_psd_step_three);
        initView();
    }

    private void initView() {
        binding.tvBackLogin.setOnClickListener(this);
        CountDownHelper countDownHelper = new CountDownHelper(binding.tvTimeBack, "", "", 3, 1);
        countDownHelper.start();
        countDownHelper.setOnFinishListener(new CountDownHelper.OnFinishListener() {
            @Override
            public void finish() {
                if (!isFinishing()) {
                    goLogin();
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_back_login:
                goLogin();
                break;
        }
    }

    private void goLogin() {
        AppManager.getAppManager().finishAll();
        String json = (String) SharedPreferenceUtils.getInstance().get(ModifyLoginPsdStepThreeActivity.this, Constant.LOGIN_ACCOUNT_RECORD, "");
        LoginAccountRecordModel loginAccountRecordModel = GsonUtils.gsonToBean(json, LoginAccountRecordModel.class);
        if (loginAccountRecordModel != null && loginAccountRecordModel.getLoginRecord() != null && loginAccountRecordModel.getLoginRecord().size() > 0) {
            ArrayList<String> loginRecord = loginAccountRecordModel.getLoginRecord();
            LoginTwoActivity.callMe(ModifyLoginPsdStepThreeActivity.this, loginRecord);
        } else {
            LoginActivity.callMe(ModifyLoginPsdStepThreeActivity.this, null);
        }
    }

    @Override
    public void onBackPressed() {

    }

}